//
//  HomePageViewController.m
//  ZhiHuiLiJiang
//
//  Created by Work on 2018/11/12.
//  Copyright © 2018年 王雅鹏. All rights reserved.
//首页VC

#import "HomePageViewController.h"
#import "SearchView.h"//首页头部View
#import "BYHomeTopCarouselModel.h"//首页上方轮播图model
#import "BYHomeInfoCarouselModel.h"//首页资讯轮播的model
#import "MyCollectionViewCell.h"//首页推荐菜单的cell
#import "BYHomeRecommendMenuModel.h"//首页推荐菜单的model
#import "TodayHeaderView.h"//公告资讯的View
#import "MyTwoCollectionViewCell.h"//首页大模块菜单的cell
#import "BYHomeMajorMenuModel.h"//首页大模块菜单的model
#import "HWScanViewController.h"
#import "LLSearchViewController.h"
#import "BYFootView.h"
#import "CoreLocation/CoreLocation.h"
#import "BYChangeCityViewController.h"
#import "WXApiObject.h"
#import "WXApi.h"
#import "BYUserManager.h"
#import "BYSetModel.h"

@interface HomePageViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,CLLocationManagerDelegate>
/**首页上方的View*/
@property (nonatomic,strong) SearchView *homeTopView;
/**瀑布流*/
@property (nonatomic,strong) UICollectionView * collectioneView;
/**公告资讯的View*/
@property (nonatomic ,strong) TodayHeaderView *horseInfoView;
/**上方轮播图的数据源数组*/
@property(nonatomic,strong)NSArray *topCarDataArr;
/**推荐菜单的数据源数组*/
@property(nonatomic,strong)NSArray *recomdMenuDataArr;
/**大模块菜单的数据源数组*/
@property(nonatomic,strong)NSArray *majorMenuDataArr;

@property (strong, nonatomic) CLLocationManager* locationManager;

@property (assign, nonatomic) double latitude;

@property (assign, nonatomic) double longitude;

@property (assign, nonatomic) NSInteger time;

@property (strong, nonatomic) UIImageView *BottomimageView;



@end
@implementation HomePageViewController
#pragma mark- init初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    self.latitude = [@"26.86" doubleValue];
    self.longitude =[@"100.25" doubleValue];
    [self setupUI];
    [self addSubViewClick];
    [self getHomeMajorMenu];//请求大模块菜单
    [self getWeatherData];
    [self load];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(load) name:BYSetting object:nil];
    
}
- (void)setupUI{
    self.view.backgroundColor = [UIColor whiteColor];
    //状态栏的颜色
    UIImageView *stateBGImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,BY_ScreenWidth,BY_StatusBar_H)];
    stateBGImgView.image = [UIImage imageNamed:@"homeStateBgIcon"];
    [self.view addSubview:stateBGImgView];
    
    //头部的View
    _homeTopView = [[SearchView alloc]initWithFrame:CGRectMake(0, BY_StatusBar_H, BY_ScreenWidth, BY_Height(235+237))];
    _homeTopView.image = [UIImage imageNamed:@"homeBackGround"];
    [self.view addSubview:_homeTopView];
    
    //瀑布流
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置collectionView滚动方向
    //    [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    self.collectioneView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, BY_Height(235+237)+BY_StatusBar_H, BY_ScreenWidth, BY_ScreenHeight - BY_Height(235+237) - BY_StatusBar_H - BY_Bot_H - 49) collectionViewLayout:layout];
    self.collectioneView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.collectioneView];
    self.collectioneView.backgroundColor =  [UIColor clearColor];
    //3.注册collectionViewCell
    //注意，此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致 均为 cellId
    [self.collectioneView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:@"cellId"];
    [self.collectioneView registerClass:[MyTwoCollectionViewCell class] forCellWithReuseIdentifier:@"MyTwoCollectionViewCell"];

    //注册headerView  此处的ReuseIdentifier 必须和 cellForItemAtIndexPath 方法中 一致  均为reusableView
    [self.collectioneView registerClass:[TodayHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView"];
    [self.collectioneView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"HeaderView"];  //  一定要设置

    //4.设置代理
    self.collectioneView.delegate = self;
    self.collectioneView.dataSource = self;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
    if (self.tabBarController.tabBar.isHidden) {
        self.tabBarController.tabBar.hidden = NO;
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden=NO;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    NSLog(@"内存警告");
}

#pragma mark- 用户交互
- (void)addSubViewClick{
    BY_kWeakSelf(ws);
    _homeTopView.clickSeachBtn = ^{
        LLSearchViewController *seachVC = [[LLSearchViewController alloc] init];
        [ws.navigationController pushViewController:seachVC animated:YES];

    };
    _homeTopView.clickScanBtn = ^{
        HWScanViewController *VC = [[HWScanViewController alloc]init];
        [ws.navigationController pushViewController:VC animated:YES];
    };
    _homeTopView.clickRotationIconView = ^(NSInteger index) {
        [ws cycleScrollViewIconClick:index];
    };
    _homeTopView.clickAddnBtn = ^{
        BYChangeCityViewController *seachVC = [[BYChangeCityViewController alloc] init];
        seachVC.clickStr = ^(NSString *str, double la, double lo) {
            ws.homeTopView.cityLab.text  =str;
            ws.longitude =lo;
            ws.latitude =la;
            [ws getWeatherData];

        } ;
        [ws.navigationController pushViewController:seachVC animated:YES];
        
    };

}
- (void)cycleScrollViewIconClick:(NSInteger)index{//点击了轮播图
    NSLog(@"点击了轮播图：%tu",index);
    if (_topCarDataArr.count > 0) {
        BYHomeTopCarouselModel *topCarModel = _topCarDataArr[index];
        if (topCarModel.carousel_type == 0) {//直接跳转
            BYWebVC *webVC = [[BYWebVC alloc]init];
            webVC.url = topCarModel.url;//@"http://www.tianhuicity.com/m";
            webVC.titleStr = topCarModel.carousel_title;//@"商业";
            [self.navigationController pushViewController:webVC animated:YES];
        }else if (topCarModel.carousel_type == 1){//验证跳转,打开第三方app
            NSLog(@"需要验证，然后跳转到第三方app");
        }else if (topCarModel.carousel_type == 2){//主app内部
            NSLog(@"跳转到主app内部");
        }else{
            NSLog(@"未知的跳转类型");
        }
    }
}

#pragma mark- 网络请求
- (void)getCarouselIcons:(NSString *)numStr{//请求轮播图
    BY_kWeakSelf(ws);
    [BYNetworking requestGetOrPostWithType:GET url:LJURL_HomeTop_carousel params:@{@"size": numStr} success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        NSArray *dataArr = [data objectForKey:@"data"];
        NSMutableArray *dataArrM = [NSMutableArray arrayWithCapacity:dataArr.count];
        for (NSDictionary *dic in dataArr) {
            BYHomeTopCarouselModel *topCarouselModel = [BYHomeTopCarouselModel mj_objectWithKeyValues:dic];
            [dataArrM addObject:topCarouselModel];
        }
        ws.topCarDataArr = dataArrM.copy;
        ws.homeTopView.topCarDataArr = ws.topCarDataArr;
        
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:YES];
}
- (void)getHomeRecommendMenu:(NSString *)numStr{//请求推荐的菜单
    BY_kWeakSelf(ws);
    [BYNetworking requestGetOrPostWithType:GET url:LJURL_HomeMenu_recommend params:@{@"size": numStr} success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        NSLog(@"获取推荐的菜单:%@",data);
        NSArray *dataArr = [data objectForKey:@"data"];
//        //测试数据
        NSMutableArray *dataArrM = [NSMutableArray arrayWithCapacity:dataArr.count];
        for (NSDictionary *dic in dataArr) {
            BYHomeRecommendMenuModel *homeRecommendMenuModel = [BYHomeRecommendMenuModel mj_objectWithKeyValues:dic];
            [dataArrM addObject:homeRecommendMenuModel];
        }
        
        ws.recomdMenuDataArr = dataArrM.copy;
        [ws.collectioneView reloadData];
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:YES];
}
- (void)getInfoCarouselData:(NSString *)numStr{//请求资讯轮播
    BY_kWeakSelf(ws);
    [BYNetworking requestGetOrPostWithType:GET url:LJURL_HomeInfo_carousel params:@{@"size": numStr} success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        
        NSArray *dataArr = [data objectForKey:@"data"];
        NSMutableArray *dataArrM = [NSMutableArray arrayWithCapacity:dataArr.count];
        for (NSDictionary *dic in dataArr) {
            BYHomeInfoCarouselModel *infoCarouselModel = [BYHomeInfoCarouselModel mj_objectWithKeyValues:dic];
            [dataArrM addObject:infoCarouselModel];
        }
        ws.horseInfoView.dataArr =  dataArrM.copy;
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:NO];
}
- (void)getHomeMajorMenu{//请求大模块菜单
    BY_kWeakSelf(ws);
    [BYNetworking requestGetOrPostWithType:GET url:LJURL_HomeMenu_major params:@{} success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        NSLog(@"获取大模块菜单:%@",data);
        NSArray *dataArr = [data objectForKey:@"data"];
        NSMutableArray *dataArrM = [NSMutableArray arrayWithCapacity:dataArr.count];
        for (NSDictionary *dic in dataArr) {
            BYHomeMajorMenuModel *homeMajorMenuModel = [BYHomeMajorMenuModel mj_objectWithKeyValues:dic];
            [dataArrM addObject:homeMajorMenuModel];
        }
        
        ws.majorMenuDataArr = dataArrM.copy;
        [ws.collectioneView reloadData];
        
    } fail:^(NSError * _Nonnull error) {
        
    } showHUD:YES];
}
- (void)getWeatherData{
    NSDictionary *paramsDic = @{@"lat":[NSString stringWithFormat:@"%f",self.latitude],
                                @"lon":[NSString stringWithFormat:@"%f",self.longitude],
                                };
    NSLog(@"经纬度：%@",paramsDic);
    [BYNetworking requestGetOrPostWithType:GET url:LJURL_HomeWeather params:paramsDic success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
        id dataDict = [data objectForKey:@"data"];
        if (![dataDict isKindOfClass:[NSDictionary class]]) {
            return ;
        }
        NSDictionary *dataDic =dataDict;
        //获取pm10和pm2.5的数据
        NSDictionary *aqiDic = BYSafeDict([dataDic objectForKey:@"aqi"]);
        if (![aqiDic isEqualToDictionary:@{}]) {
            NSString *pmTenStr = BYSafeStr([aqiDic objectForKey:@"pm10"]);//pm10
            NSString *pmTwoStr = BYSafeStr([aqiDic objectForKey:@"pm25"]);//pm25
            [self.homeTopView setPMTenStr:pmTenStr pmTwoStr:pmTwoStr];
        }
        //获取城市名称：
        NSDictionary *cityDic = BYSafeDict([dataDic objectForKey:@"city"]);
        if ([cityDic isEqualToDictionary:@{}]) {
            return ;
        }
        NSString *cityStr = BYSafeStr([cityDic objectForKey:@"gaode_city"]);//城市
        NSString *districtStr = BYSafeStr([cityDic objectForKey:@"gaode_district"]);//区域
    
        //获取当前是白天还是夜晚
        NSString *currentTimeStr = BYSafeStr([dataDic objectForKey:@"time"]);//当前时间
        NSDictionary *forecastDic = BYSafeDict([dataDic objectForKey:@"forecast"]);
        if ([forecastDic isEqualToDictionary:@{}]) {
            return ;
        }
        NSString *sunriseStr = BYSafeStr([forecastDic objectForKey:@"sunrise"]);//日出时间
        NSString *sunsetTimeStr = BYSafeStr([forecastDic objectForKey:@"sunset"]);//日落时间
        if (!(currentTimeStr.length>0 && sunriseStr.length>0 &&sunsetTimeStr.length>0)) {
            return ;
        }
       BOOL isDay = [self getCurrentTimeIsDay:currentTimeStr sunrise:sunriseStr sunset:sunsetTimeStr];//是否是白天
        
        //获取温度和天气情况
        NSString *currentTempStr = @"";//实时温度
        NSString *tempNightStr = BYSafeStr([forecastDic objectForKey:@"tempnight"]);//夜间温度
        NSString *tempDayStr = BYSafeStr([forecastDic objectForKey:@"tempday"]);//白天温度
        NSString *conditionStr=@"";//天气
        NSString *weatherIconStr=@"";
        if (isDay) {//白天
            currentTempStr = tempDayStr;//白天温度
            conditionStr = BYSafeStr([forecastDic objectForKey:@"conditionday"]);//白天天气：多云
            NSString *conditioniddayStr = BYSafeStr([forecastDic objectForKey:@"conditionidday"]);
            weatherIconStr = [NSString stringWithFormat:@"day_%@",conditioniddayStr];
        }else{//夜晚
            currentTempStr = tempNightStr;//夜间温度
            conditionStr = BYSafeStr([forecastDic objectForKey:@"conditionnight"]);//夜间天气：多云
            NSString *conditionidnightStr = BYSafeStr([forecastDic objectForKey:@"conditionidnight"]);
            weatherIconStr = [NSString stringWithFormat:@"night_%@",conditionidnightStr];
        }
        self.homeTopView.currentTempStr = currentTempStr;//实时温度
        self.homeTopView.weatherStr = conditionStr;//天气：多云
        
        //时间转换为yyyy-MM-dd
       NSString *timeYMDStr = [BYRegular dateStr:currentTimeStr currentFromatter:@"yyyy-MM-dd HH:mm:ss" nowFromatter:@"yyyy-MM-dd"];
        //获取是星期几
        NSString *weekDayStr = [BYRegular getCurrentDateWeekDay:timeYMDStr];
        self.homeTopView.temperatureStr = [NSString stringWithFormat:@"%@%@ %@ %@/%@℃",cityStr,districtStr,weekDayStr,tempNightStr,tempDayStr];
        self.homeTopView.weatherIconStr = weatherIconStr;
        //预警信息
        NSString *warningMsg = @"";
        if (BYValidArray([dataDic objectForKey:@"alert"])) {
            NSArray *alertArr = [dataDic objectForKey:@"alert"];
            if (alertArr.count > 0) {
                NSDictionary *alertDic = alertArr[0];
                warningMsg = [alertDic objectForKey:@"alert_type"];
            }
        }
        NSLog(@"天气预警：%@",warningMsg);// @"大风蓝色";
        self.homeTopView.warningStr = warningMsg;
    } fail:^(NSError * _Nonnull error) {
    } showHUD:YES];
}
- (BOOL)getCurrentTimeIsDay:(NSString *)currentTimeStr sunrise:(NSString *)sunriseStr sunset:(NSString *)sunsetTimeStr{//当前时间、日出时间、日落时间---返回是否是白天
    NSLog(@"%@---%@---%@",currentTimeStr,sunriseStr,sunsetTimeStr);
    //判断是否日出（日出时间<当前时间）
    BOOL isChu;
    NSInteger chuNum = [BYRegular compareDate:currentTimeStr withDate:sunriseStr];
    if (chuNum == -1) {//日出了
        isChu = YES;
    }else{
        isChu = NO;
    }
    //判断是否已日落（日出时间<当前时间）
    BOOL isLuo;
    NSInteger luoNum = [BYRegular compareDate:currentTimeStr withDate:sunsetTimeStr];
    if (luoNum==-1) {//日落了
        isLuo = YES;
    }else{//日未落
        isLuo = NO;
    }
    //日出后日落前是白天
    NSString *dayOrNight = (isChu && !isLuo) ? @"白天":@"夜晚";
    NSLog(@"是：%@",dayOrNight);
    return (isChu && !isLuo);
}

#pragma mark- 数据处理
- (NSArray *)recomdMenuDataArr{
    if (!_recomdMenuDataArr) {
        _recomdMenuDataArr = [NSArray array];
    }
    return _recomdMenuDataArr;
}
- (NSArray *)majorMenuDataArr{
    if (!_majorMenuDataArr) {
        _majorMenuDataArr = [NSArray array];
    }
    return _majorMenuDataArr;
}

#pragma mark- collectionView设置
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section ==0) {
        return _recomdMenuDataArr.count;
    }else{
        return _majorMenuDataArr.count;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
        MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
        if (_recomdMenuDataArr.count > 0) {
            BYHomeRecommendMenuModel *model = _recomdMenuDataArr[indexPath.row];
            if (indexPath.row == 9) {
                model.name = @"全部";
            }
            cell.homeMenuModel = model;
        }
        return cell;
    }else{
        MyTwoCollectionViewCell *cell = (MyTwoCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MyTwoCollectionViewCell" forIndexPath:indexPath];
        if (_majorMenuDataArr.count > 0) {
            cell.majorMenuModel = _majorMenuDataArr[indexPath.row];
        }
        return cell;
    }
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{//设置每个item的尺寸
    if (indexPath.section == 0) {
        return CGSizeMake((BY_ScreenWidth - BY_Width(48+4*10))/5.0, BY_Width(72)+BY_Height(16+28+20));
    }
    return CGSizeMake((BY_ScreenWidth - BY_Width(48+16))/2.0, BY_Width(148));
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{//设置每个item的UIEdgeInsets
    return UIEdgeInsetsMake(BY_Height(30), BY_Width(24), BY_Height(14), BY_Width(24));
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{//设置每个item水平间距
    if (section ==0) {
        return BY_Width(10);
    }
    return BY_Height(12);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{//设置每个item垂直间距
    if (section ==0) {
        return BY_Height(10);
    }
    return BY_Height(12);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(self.view.frame.size.width, 0);
    }else{
        return CGSizeMake(self.view.frame.size.width, BY_Height(92+20*2 + 9));
    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(self.view.frame.size.width, 0);
    }else{
        
        return CGSizeMake(self.view.frame.size.width,40);
    }
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    //通过设置SupplementaryViewOfKind 来设置头部或者底部的view，其中 ReuseIdentifier 的值必须和 注册是填写的一致，本例都为 “reusableView”
    if ([kind isEqualToString:@"UICollectionElementKindSectionHeader"]) {
        self.horseInfoView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView" forIndexPath:indexPath];
        if (indexPath.section == 1) {
            BY_kWeakSelf(ws);
            self.horseInfoView.clickHorseRaceLampRow = ^(NSString *urlStr) {
                NSLog(@"点击了首页跑马灯：%@",urlStr);
                BYWebVC *webVC = [[BYWebVC alloc]init];
                webVC.url = urlStr;
                webVC.titleStr = @"公告资讯";
                [ws.navigationController pushViewController:webVC animated:YES];
            };
            return self.horseInfoView;
        }else{
            UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"reusableView" forIndexPath:indexPath];
            headerView.backgroundColor =[UIColor whiteColor];
            return headerView;
            return nil;
        }
    }
    else{
        
        if (indexPath.section == 1) {
            UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
            [headerView addSubview: self.BottomimageView];
            return headerView;
            
        }
        return nil;

    }
}
-(UIImageView *)BottomimageView{
    if (!_BottomimageView) {
        _BottomimageView = [[UIImageView alloc] initWithFrame:CGRectMake(KSCREEWIDTH/2-102, 5, 204, 16)];
        _BottomimageView.image = [UIImage imageNamed:@"底线"];
    }
    return _BottomimageView;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{//点击item方法
//    MyCollectionViewCell *cell = (MyCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    if (indexPath.section == 0) {//推荐菜单
        BYHomeRecommendMenuModel *recomMenuModel = self.recomdMenuDataArr[indexPath.row];
        
        
        if ([recomMenuModel.name isEqualToString:@"全部"]) {
            self.tabBarController.selectedIndex = 2;
            }
        else{
            
            NSDictionary *dict1 = @{@"uuid":[SaveCacheData loadDataStrWithKey:currentUserudid]==NULL?@"none":[SaveCacheData loadDataStrWithKey:currentUserudid],@"time":@([[self getNowTimeTimestamp3] integerValue]),@"mid":recomMenuModel.mid,@"type":@([self type:recomMenuModel.type])};
            
            [BYNetworking requestGetOrPostWithType:POST url:LJURL_open_mune params:dict1 success:^(NSInteger code, NSString * _Nonnull msg, id  _Nonnull data) {
                
            } fail:^(NSError * _Nonnull error) {
                
                
            } showHUD:YES];

            if(recomMenuModel.type == 3){//小程序
                BOOL isWX = [WXApi isWXAppInstalled];//是否安装微信（YES已安装、NO未安装)
                if (isWX) {
                    NSDictionary *dict = [self dictionaryWithJsonString:[recomMenuModel.url stringByReplacingOccurrencesOfString:@"\n" withString:@""]];
                    WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                    launchMiniProgramReq.userName = dict[@"userName"];  //拉起的小程序的username
                    launchMiniProgramReq.path =  dict[@"path"];;    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                    launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                    [WXApi sendReq:launchMiniProgramReq];
                }else{
                    NSString *xcxUrl = @"";
                    if ([recomMenuModel.mid isEqualToString:@"jinpaijieshuo"]) {//金牌解说
                        xcxUrl = noWeChatJieShuo;
                    }else if ([recomMenuModel.mid isEqualToString:@"yunFoodBooking"]){//智慧食堂
                        xcxUrl = noWeChatShiTang;
                    }else{
                    }
                    BYWebVC *webVC = [[BYWebVC alloc]init];
                    webVC.url = xcxUrl;
                    webVC.titleStr = recomMenuModel.name;
                    [self.navigationController pushViewController:webVC animated:YES];
                }
            }
            else{
                BYWebVC *webVC = [[BYWebVC alloc]init];
                webVC.url = recomMenuModel.url;//@"https://m.kuaidi100.com/app/?coname=cmb&hdisplay=web";
                webVC.titleStr = recomMenuModel.name;// @"我的快递";
                [self.navigationController pushViewController:webVC animated:YES];
                
            }


        }
    }else{//六大模块
        BYHomeMajorMenuModel *majorMenuModel = self.majorMenuDataArr[indexPath.row];
        BYWebVC *webVC = [[BYWebVC alloc]init];
        webVC.url = majorMenuModel.url;//@"http://www.tianhuicity.com/m";
        webVC.titleStr = majorMenuModel.name;//@"智慧商业";
        [self.navigationController pushViewController:webVC animated:YES];

    }
}
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {if (jsonString == nil) {return nil;}NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];NSError *err;NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];if(err) {NSLog(@"json解析失败：%@",err);return nil;}return dic;}

-(NSString *)getNowTimeTimestamp3{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    
    return timeSp;
}

-(NSInteger )type:(NSInteger)type{
    if (type ==0 ||type ==2 ) {
        
        return 1;
    }
    else{
        return 2;

    }
}
-(void)load{
    for (BYSetModel *model in APPDELEGATE.SetDataArray) {
        if ([model.setting_name isEqualToString:@"menu-commend-size"]) {
            [self getHomeRecommendMenu:[NSString stringWithFormat:@"%ld",[model.setting_value integerValue] +1]];//请求推荐的菜单
        }
        if ([model.setting_name isEqualToString:@"info-carousel-size"]) {
            [self getInfoCarouselData:model.setting_value];//请求资讯轮播
        }
        if ([model.setting_name isEqualToString:@"info-carousel-size"]) {
            [self getCarouselIcons:model.setting_value];//请求轮播图
        }
    }
    
}
@end
